﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

using ZFB.Common;
using ZFB.IServices;

namespace ZFB.WebAPI.Controllers
{
    /// <summary>
    /// 配置项
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SettingController : ControllerBase
    {
        private readonly ISettingServices settingServices;

        public SettingController(ISettingServices settingServices)
        {
            this.settingServices = settingServices;
        }
        /// <summary>
        /// 获取所有配置
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> GetAll()
        {
            return await settingServices.GetAllAsnyc();
        }
        /// <summary>
        /// 获取配置 string
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> GetValue(string name)
        {
            return await settingServices.GetValueAsnyc(name);
        }
        /// <summary>
        /// 获取配置 int
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> GetIntValue(string name)
        {
            return await settingServices.GetlntValueAsnyc(name);
        }
        /// <summary>
        /// 获取配置 bool
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> GetBoolValue(string name)
        {
            return await settingServices.GetBoolValueAsnyc(name);
        }
        /// <summary>
        /// 添加配置或更新配置 string
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> SetValue(string name,string value)
        {
          return await settingServices.SetValueAsnyc(name,value);
        }
        /// <summary>
        /// 添加配置或更新配置 int
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> SetIntValue(string name, int value)
        {
            return await settingServices.SetValueAsnyc(name, value);
        }
        /// <summary>
        /// 添加配置或更新配置 bool
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> SetBoolValue(string name, bool value)
        {
            return await settingServices.SetValueAsnyc(name, value);
        }
    }
}
